package com.jiangdong.eureka.consumer.controller;

import com.jiangdong.eureka.consumer.entitys.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
public class ConsumerController {

    @Autowired
    RestTemplate restTemplate;

    @GetMapping("/consumer/test/{number}")
    public String home(@PathVariable(name = "number") String number){
        String res = restTemplate.getForEntity("http://localhost:8081/test/" + number,String.class).getBody();
        return "get value from service --->" + res;
    }

    @GetMapping("/consumer/test/post/{number}")
    public String postTest(@PathVariable(name = "number") String number){
        Student student = new Student();
        ResponseEntity<String> responseEntity = restTemplate.postForEntity("http://localhost:8081/test/post?id=" + number,student,String.class);
        return "get value from service --->" + responseEntity.toString();
    }
}
